|
|
|
|
|
|
|
Given the approach used in this solution, the DisplayValue function becomes fairly straightforward. |
|
|
|
|
|
|
|
|
When the data type is a string value, the function initializes a string buffer to the correct length and passes it to the API function with the ByVal operator. This ensures that the necessary Unicode-to-ANSI conversion takes place when the function is called. The function doesn't handle the REG_MULTI_SZ function in this example because parsing this kind of string is a straightforward Visual Basic exercise (which I encourage you to try). This kind of string contains multiple strings separated by NULL characters, with two NULL characters at the end of the final string. |
|
|
|
|
|
|
|
|
When the data type is a Long value, the function passes a Long variable as a parameter. This causes the parameter to be passed by reference. |
|
|
|
|
|
|
|
|
When the data type is binary, the function dimensions a byte array to the correct length, then passes the first byte of the array by reference. This effectively passes a pointer to the start of the byte array. The DisplayValue function follows: |
|
|
|
|
|
|
|
|
Private Sub DisplayValue(ByVal hKey As Long, ByVal ValueName As String)
Dim BufferSize As Long
Dim DataType As Long
Dim buffer As String
Dim longdata As Long
Dim binarydata() As Byte
Dim res As Long
Dim LabelOutput As String
Dim x As Long
Dim hexval As String
' First get the data type and buffer size
res = RegQueryValueEx(hKey, ValueName, 0, DataType, ByVal 0&, BufferSize)
' This should always succeed, since we loaded the value name earlier
If res = 0 Then
Select Case DataType
Case REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ
LabelOutput = "String: "
buffer = String$(BufferSize, 0)
res = RegQueryValueEx(hKey, ValueName, 0, DataType, _
ByVal buffer, BufferSize)
LabelOutput = LabelOutput & Left$(buffer, Len(buffer) - 1)
' Parsing out the REG_MULTI_SZ string is left as an exercise
' to the reader
Case REG_DWORD
LabelOutput = "DWORD: "
res = RegQueryValueEx(hKey, ValueName, 0, DataType, _ |
|
|
|
|
|